<template>
	<view>
		<view class="code-box">
			<view class="list-box" v-for="(item,index) in list" :key="index" @click="listRouter(item)">
				<image class="box-img" :src="item.icon" mode=""></image>
				<view class="box-right">
					<view class="box-title">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {baseUrl} from '../../api/index.js'
	import {homeCenters,homeCentersBooks} from '../../api/api.js'
	export default {
		data() {
			return {
				list:[],
				showOptionalCourse:true,
				type: 0
			}
		},
		onLoad(query) {
			uni.setNavigationBarTitle({
			    title:query.title
			})
			this.type = query.type
			if(query.type == 0){
				this.getHomeCentersBooks(query.type,query.module)
			}else{
				this.addRandomData(query.type,query.module)
			}
			
		},
		// onShow() {
		// 	this.getBooksDetail()
		// },
		methods: {
			getHomeCentersBooks(type,module){
				homeCentersBooks({module:module}).then(resp=>{
					resp.forEach(item=>{
						item.icon = baseUrl + item.icon
					})
					this.list = resp
				})
			},
			addRandomData(type,module) {
				this.list = []
				homeCenters({size:1000,page: 1, type: type,module: module}).then(resp=>{
					this.list = resp.content
				})
			},
			listRouter(item){
				if(this.type == 0){
					let itemObj = JSON.stringify(item)
					uni.navigateTo({
						url:`../list/list?item=${itemObj}`
					})
				}else{
					uni.navigateTo({
						url:`/pages/detail/detail?id=${item.resourceId}&title=${item.name}`
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
.code-box{
	padding: 30rpx;
	.list-box{
		height: 100rpx;
		margin-bottom: 30rpx;
		.box-img{
			width: 100rpx;
			height: 100rpx;
			border-radius: 10rpx;
			float: left;
		}
		.box-right{
			margin-left: 120rpx;
			.box-title{
				height: 100rpx;
				line-height: 100rpx;
				font-size: 36rpx;
				text{
					font-size: 28rpx;
					display: inline-block;
					margin-right: 20rpx;
					color: #000;
					opacity: 0.45;
				}
				text:first-child{
					background-color: #F8F9F9;
					border-radius: 5rpx;
					padding: 0 10rpx;
				}
				text:last-child{
					border-left: #ccc solid 2rpx;
					padding-left: 20rpx;
				}
			}
		}
		:after{
			content: "";
			height: 0;
			line-height: 0;
			display: block;
			visibility: hidden;
			clear: both;
		}
	}
}
</style>
